import { RoleHelper } from "./base.role"

export class Repairer implements IRole {
    role: RoleType = 'repairer';
    bodyPart: BodyPartConstant[] = [WORK, CARRY, MOVE];
    priority: number = 5;
    minCost: number = 200;

    work(creep: Creep) {
        this.stateSwitch(creep);

        if (creep.memory.working) {
            // 维修
        } else {
            // 1. 获取存储的能源
            if (RoleHelper.getStoreEnergy(creep)) {
                return;
            }

            // 2. 拾取地上的能源
            if (RoleHelper.pickupEnergy(creep)) {
                RoleHelper.harvestEnergy(creep);
                return;
            }

            // 3. 采集能源
            if (RoleHelper.harvestEnergy(creep)) {
                return;
            }

            return;
        }
    }

    stateSwitch(creep: Creep) {
        if (creep.memory.working === undefined) {
            creep.memory.working = false;
        }

        if (creep.store.getFreeCapacity() === 0) {
            // 背包满了，切换至维修状态
            creep.memory.working = true;
        } else if (creep.store.getUsedCapacity() === 0) {
            // 背包空了，切换至取能状态
            creep.memory.working = false;
        }
    }

}